package com.boot.security.server.dao.mffl;

import java.util.List;
import java.util.Map;

import com.boot.security.server.model.mffl.Vo.OrderVo;
import org.apache.ibatis.annotations.*;

import com.boot.security.server.model.mffl.MfflOrder;

@Mapper
public interface MfflOrderDao {

    //按商户号---行锁查询
    @Select("BEGIN;SELECT * FROM mffl_order t WHERE t.pay_merchant_number = #{paymerchantnumber} FOR UPDATE;COMMIT;")
    MfflOrder getByPaymerchantNumberlocking(String paymerchantnumber);

    //按商户号---普通查询
    @Select("select * from mffl_order t where t.pay_merchant_number = #{paymerchantnumber}")
    MfflOrder getBypaymerchantnumber(String paymerchantnumber);

    @Select("select * from mffl_order t where t.id = #{id}")
    MfflOrder getById(Long id);

    @Delete("delete from mffl_order where id = #{id}")
    int delete(Long id);

    int update(MfflOrder mfflOrder);
    
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into mffl_order(pay_number, pay_merchant_number, servier_id, service_name, money, userid, createTime, updtaeTime, delete_stae, deleteTime, typeid, product_id, state) values(#{payNumber}, #{payMerchantNumber}, #{servierId}, #{serviceName}, #{money}, #{userid}, #{createTime}, #{updtaeTime}, #{deleteStae}, #{deleteTime}, #{typeid}, #{productId}, #{state})")
    int save(MfflOrder mfflOrder);
    
    int count(@Param("params") Map<String, Object> params);
    List<MfflOrder> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //后台专业咨询订单列表
    int orderCount(@Param("params") Map<String, Object> params);
    List<OrderVo> orderList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //后台打赏列表
    int awardCount(@Param("params") Map<String, Object> params);
    List<OrderVo> awardList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    @Update("update mffl_order set delete_stae = 0,deleteTime=now() where product_id = #{id}")
    void deleteOrderByProductId(@Param("id") Long id);
    @Update("update mffl_order set state = #{state} where id = #{id} ")
    void updateState(@Param("id") Integer orderid, @Param("state") int i);

    List<OrderVo> getOrderListByPayState5();
}
